import java.util.Arrays;

class Student implements Comparable<Student>{
    public int age;
    public String name;

    public Student(int age, String name) {
        this.age = age;
        this.name = name;
    }

    @Override
    public int compareTo(Student o) {
        if(this.age > o.age) {
            return 1;
        } else if(this.age < o.age) {
            return -1;
        }else {
            return 0;
        }
    }
    @Override
    public String toString() {
        return "Student{" +
                "age=" + age +
                ", name='" + name + '\'' +
                '}';
    }
}
public class Test {
    public static void main(String[] args) {
        Student[] students = new Student[3];
        students[0] = new Student(18,"小丁");
        students[1] = new Student(12,"小花");
        students[2] = new Student(21,"小红");
        Arrays.sort(students);
        System.out.println(Arrays.toString(students));
    }
}
